package com.zijiebutiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zijiebutiao.pojos.TUser;
import com.zijiebutiao.service.TUserService;
import com.zijiebutiao.mapper.TUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author ZhangQingTian
* @description 针对表【t_user】的数据库操作Service实现
* @createDate 2023-02-28 15:59:34
*/
@Transactional(rollbackFor = Exception.class)
@Service
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser>
    implements TUserService{
    @Autowired
    private TUserMapper userMapper;
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Override
    public boolean login(TUser user) {
        LambdaQueryWrapper<TUser> wrapper= Wrappers.lambdaQuery();
        wrapper.eq(TUser::getUsername,user.getUsername());
        TUser tUser=this.getOne(wrapper);
        if (tUser!=null){
          return passwordEncoder.matches(user.getPassword(),tUser.getPassword());
        }
        return false;
    }
}




